/**
 * @author pmackay
 */



//window.onload = init;
function init_dashboard(){
    //alert("foo");
    countdown(2009, 10, 24);
	update350Feeds();
}

/*
 * Copied from http://www.javascriptkit.com/script/script2/count2.shtml
 */
var before = "Christmas!"
var current = "Today is Christmas. Merry Christmas!"
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
function countdown_test(yr, m, d){
    document.getElementById("countdown").firstChild.nodeValue = '1'
}

function countdown(yr, m, d){
    theyear = yr;
    themonth = m;
    theday = d
    var today = new Date();
    var todayy = today.getYear()
    
	if (todayy < 1000) {
        todayy += 1900;
    }
    var todaym = today.getMonth();
    var todayd = today.getDate()
    var todayh = today.getHours()
    var todaymin = today.getMinutes()
    var todaysec = today.getSeconds()
    var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
	futurestring=montharray[m-1]+" "+d+", "+yr
    dd = Date.parse(futurestring) - Date.parse(todaystring)
    dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1)
    dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1)
    dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1)
    dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1)
    
	if (dday == 0 && dhour == 0 && dmin == 0 && dsec == 1) {
        document.getElementById("countdown").firstChild.nodeValue = current
        return
    }
    else 
        document.getElementById("countdown").firstChild.nodeValue = dday + "." + dhour + ":" + dmin + ":" + dsec
		document.getElementById("daysCountdown").firstChild.nodeValue = dday
		document.getElementById("hoursCountdown").firstChild.nodeValue = dhour
		document.getElementById("minutesCountdown").firstChild.nodeValue = dmin
		document.getElementById("secondsCountdown").firstChild.nodeValue = dsec
    setTimeout("countdown(theyear,themonth,theday)", 1000)
}

function update350Feeds(){
	try {netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');} catch(e) {}
	new Ajax.Request('http://pipes.yahoo.com/pipes/pipe.run?_id=goylEUtz3hGUzCdf0EypaA&_render=json', {
  		onComplete: function(transport) {
			document.getElementById("status").firstChild.nodeValue = transport.status
//			var totalsFeed = eval('('++')');
			var totalsFeed = transport.responseText.evalJSON(true);
			document.getElementById("actionsTotal").firstChild.nodeValue = totalsFeed['value']['items'][0]['actions'];
			document.getElementById("countriesTotal").firstChild.nodeValue = totalsFeed['value']['items'][1]['countries'];
	  	}
	}); //['items']

}
